<template>
  <div class="pushInfoList">
  	<x-header :left-options="{backText: '',preventGoBack:true}">消息中心</x-header>		
  	<router-link to="/index" class="backIndex"><span>&nbsp;</span></router-link>
  	<!--数据加载动画 start-->
		<div class="loadingBox" v-show="status == 0">
			<div class="loading">
				<div>loading..</div>
				<div></div>
				<div></div>
			</div>
		</div>
		<!--数据加载动画 end-->
  	
  	<ul class="infoForm">
  		<li class="infoList" v-for="(infoList,index) in infoForm">
  			<div class="infoListTitle" v-text="infoList.Title"></div>
  			<div class="infoListDate" v-text="substr(infoList.Date)"></div>
  			<span :data-id="infoList.ID" class="checkDetail" @click="checkDetail"></span>
  		</li>
  		<li class="checkMore" @click="loadMore" v-text="loadMoreText" v-if="infoForm.length >= 8"></li>
  	</ul>
		
	</div>
</template>

<script>
import Api from 'assets/js/api';
import init from '../assets/js/init';
import { XHeader, Actionsheet, TransferDom } from 'vux'


var result = localStorage.getItem('result');
var api = new Api();
export default {
  name: 'pushInfoList',
  data () {
    return {
			status:'0',//默认加载状态为0
			infoForm:[],
			infoFormPage:1,//初始默认flowPartyMemberForm为加载第一页，往后每点击一次加载更多则增加一页
    	infoFormLength:'',//流动党员的所有数据长度
			loadMoreText:'查看更多',
    }
  },
  created(){
  	var self = this;
  	api.get(api.url.pushInfoList,{ 
			params:{
				Action: 'XXFB_GETLASTLISTBYAPP',
				p: 1,
				pagecount: 8,
				szhlcode: result
			}
		}).then(response=>{ 
			console.log(response);
			self.infoForm = response.data.Result;
			self.infoFormLength = response.data.DataLength;
			self.status = "1";
		}).catch(err=>{ 
			console.log(err) 
		})
  },
  activated(){
  	var self = this;
  	api.get(api.url.pushInfoList,{ 
			params:{
				Action: 'XXFB_GETLASTLISTBYAPP',
				p: 1,
				pagecount: 8,
				szhlcode: result
			}
		}).then(response=>{ 
			console.log(response);
			self.infoForm = response.data.Result;
			self.infoFormLength = response.data.DataLength;
			self.status = "1";
		}).catch(err=>{ 
			console.log(err) 
		})
  },
  methods:{
  	substr(val){
  		return val.substr(0,10);
  	},
  	loadMore(){
  		this.infoFormPage += 1;
			var self = this;
			this.loadMoreText = '正在加载中···';
			api.get(api.url.pushInfoList,{ 
				params:{
					Action: 'XXFB_GETLASTLISTBYAPP',
					p: self.infoFormPage,
					pagecount: (self.infoFormLength - self.infoFormPage * 8) > 0 ? 8 : 8 - Math.abs(self.infoFormLength - self.infoFormPage * 8),
					szhlcode: result
				}
			}).then(response=>{ 
				self.infoForm = self.infoForm.concat(response.data.Result);
				self.loadMoreText = '点击加载更多';
			}).catch(err=>{ 
				console.log(err);
				this.loadMoreText = '点击加载更多';
			});
			if(this.infoForm.length == this.infoFormLength){
				this.loadMoreText = '信息已经更新为最新的了！';
			}
  	},
  	checkDetail(){
  		localStorage.removeItem('pushInfoTitle');
  		localStorage.removeItem('pushInfoContent');
  		var self = this;
  		var dataID = event.target.getAttribute('data-id');
  		var pushInfoTitle;
  		var pushInfoContent;
  		for(var  i = 0; i < self.infoForm.length; i++){
  				if(self.infoForm[i].ID == dataID){
  					pushInfoTitle = self.infoForm[i].Title;
  					pushInfoContent = self.infoForm[i].Content;
  				}
  		}
  		localStorage.setItem('pushInfoTitle',pushInfoTitle);
  		localStorage.setItem('pushInfoContent',pushInfoContent);
			this.$router.push('/pushInfoDetail');
  	}
  },
  components:{
  	XHeader,
    Actionsheet,
  },
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style>
	@import url("../assets/css/common.css");
	.pushInfoList{
		height: 100%;
	}
	.vux-header{
		background-color: #f00 !important;
		position: fixed !important;
		top: 0;
		left: 0;
		z-index: 2000;
		width: 100%;
	}
	.pushInfoList .backIndex{
		position: fixed;
    display: block;
    width: 30px;
    height: 30px;
    top: 5px;
    left: 10px;
    z-index: 2001;
	}
	.vux-header .vux-header-left .left-arrow:before{
		border: 2px solid #fff !important;
    border-width: 2px 0 0 2px !important;
	}
	.pushInfoList .infoForm{
		width: 100%;
		display: block;
		box-sizing: border-box;
		padding-top: 50px;
	}
	.pushInfoList .infoList{
		width: 100%;
		display: block;
		box-sizing: border-box;
		padding: 0.4rem 0.5rem 0.4rem 0.5rem;
		background-color: #fff;
		border-bottom: 1px solid #e9e9e9;
		position: relative;
	}
	.pushInfoList .infoListTitle{
		width: 100%;
		font-size: 0.65rem;
		color: #333;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
	}
	.pushInfoList .infoListDate{
		color: #999;
		font-size: 0.5rem;
		margin-top: 0.3rem;
		padding-bottom: 0.1rem;
	}
	.pushInfoList .checkMore{
		width: 100%;
		line-height: 1.5rem;
		color: #333;
		font-size: 0.65rem;
		text-align: center;
		background-color: #fff;
	}
	.pushInfoList .checkDetail{
		position: absolute;
		width: 100%;
		height: 100%;
		top: 0;
		left: 0;
	}
	
	/*加载动画*/
	.loadingBox{
		width: 100%;
		height: 100%;
		display: flex;
		display: -webkit-flex;
		flex-direction: column;
		-webkit-flex-direction: column;
		align-items: center;
		-webkit-align-items: center;
		justify-content: center;
		-webkit-justify-content: center;
	}
	.loading {
	    border-radius: 50%;
	    font-size: 20px;
	    height: 100px;
	    line-height: 90px;
	    position: relative;
	    text-align: center;
	    width: 100px;
	}
	.loading > div:nth-child(2) {
	    border-color: #FFF;
	    left: 0px;
	    width: 90px;
	}
	.loading > div:nth-child(3) {
	    border-color: #009933;
	    left: -5px;
	    width: 100px;
	    -webkit-animation-delay: 0.5s;
	    -moz-animation-delay: 0.5s;
	    -ms-animation-delay: 0.5s;
	    -o-animation-delay: 0.5s;
	    animation-delay: 0.5s;
	}
	.loading > div:nth-child(2), .loading > div:nth-child(3) {
	    background-color: rgba(255, 255, 255, 0.2);
	    border: 5px solid #FFF;
	    border-radius: 50%;
	    box-shadow: 0 0 5px 0 #f00;
	    height: 100px;
	    position: absolute;
	    top: 0px;
	    border-top-width: 0;
	    border-bottom-width: 0;
	    -webkit-animation: anim3 2s linear infinite;
	    -moz-animation: anim3 2s linear infinite;
	    -ms-animation: anim3 2s linear infinite;
	    -o-animation: anim3 2s linear infinite;
	    animation: anim3 2s linear infinite;
	}
	@keyframes anim3{
		0% {
		    transform: rotateY(0deg);
		}
		50% {
		    transform: rotateY(180deg);
		}
		100% {
		    transform: rotateY(360deg);
		}
	}
</style>
